
function createIframe(){
    $('#iframe_list').empty();
    var data = vm.reviewflowGraph;
    // window.reviewflowGraph = data;
    for(var i=0;i<data.length;i++){
        var iframe = document.createElement("iframe");
        iframe.style.width = '100%';
        iframe.style.height = '500px';
        var str = JSON.stringify(data[i]);
        // console.log(str);
        str = encodeURI(str);
        iframe.id = 'iframe_'+i;
        iframe.name = 'iframe_'+i;
        iframe.src = './iframe.html?'+iframe.id;
        iframe.frameBorder = 0;
        eval("sessionStorage."+iframe.id+"='"+str+"'");
        document.getElementById('iframe_list').appendChild(iframe);
        startInit(iframe.id, 500);
    }
}

var browserVersion = window.navigator.userAgent.toUpperCase();
var isOpera = browserVersion.indexOf("OPERA") > -1 ? true : false;
var isFireFox = browserVersion.indexOf("FIREFOX") > -1 ? true : false;
var isChrome = browserVersion.indexOf("CHROME") > -1 ? true : false;
var isSafari = browserVersion.indexOf("SAFARI") > -1 ? true : false;
var isIE = (!!window.ActiveXObject || "ActiveXObject" in window);
var isIE9More = (! -[1, ] == false);
function reinitIframe(iframeId, minHeight) {
    try {
        var iframe = document.getElementById(iframeId);
        var bHeight = 0;
        if (isChrome == false && isSafari == false)
            bHeight = iframe.contentWindow.document.body.scrollHeight
        var dHeight = 0;
        if (isFireFox == true)
            dHeight = iframe.contentWindow.document.documentElement.offsetHeight + 2;
        else if (isIE == false && isOpera == false)
            dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
        else if (isIE == true && isIE9More) {//ie9+
            var heightDeviation = bHeight - eval("window.IE9MoreRealHeight" + iframeId);
            if (heightDeviation == 0) {
                bHeight += 3;
            } else if (heightDeviation != 3) {
                eval("window.IE9MoreRealHeight" + iframeId + "=" + bHeight);
                bHeight += 3;
            }
        }
        else//ie[6-8]、OPERA
            bHeight += 3;
        var height = Math.max(bHeight, dHeight);
        if (height < minHeight) height = minHeight;
        iframe.style.height = height + "px";
    } catch (ex) { }
}
function startInit(iframeId, minHeight) {
    eval("window.IE9MoreRealHeight" + iframeId + "=0");
    window.setInterval("reinitIframe('" + iframeId + "'," + minHeight + ")", 300);
}
function show_nodedetail(json,target){
    var iframe = document.getElementsByTagName('iframe');
    for(var i=0;i<iframe.length;i++){
        var orgbox = window.frames[iframe[i].id].document.getElementsByClassName('OrgBox');
        for(var k=0;k<orgbox.length;k++){
            orgbox[k].style.backgroundColor = '#64b5f6';
            orgbox[k].style.color = "#333";
        }
    }
    target.style.backgroundColor = '#bbdefb';
    debugger
    vm.node_detail_list = json;
	vm.nodeDetail_Dialog = true;
}
//模态框关闭清空模态框主体数据
$('#node_detail').on('hidden.bs.modal', function (e) {
    $('#node_detail .modal-body').innerHTML = '';
})
//获取模态框几大模块内部名称
var metalist = {
    mesproductionschedule:{},//产品计划
    mesreportsheet:{},//报工单
    meswarehouseitem:{},//仓库物料
    qcpequipment:{}//设备
};
function initLoadMeta(){
    for(var key in metalist){
        var param = {
            user:vm.userinfo.user,
            type:key
        };
		
        $.ajax({
            'url':'../../app/invoke?fun=QueryMetaClass',
            'type':'post',
            'data':JSON.stringify(param),
            'success':function(response){
                if(typeof(response) == 'string'){
                    response = JSON.parse(response);
                }
                if(response.resFlag == 0){
                    metalist[response.result.internalName.toLocaleLowerCase()+''] = response.result.properties;
                }else{
                    notify(response.errMsg,'error');
                }
            }
        })
    }
    // console.log(metalist);
}

function loaddetailmsg(json,target){
    var param = {
        sql:"select * from MES_PRODUCTIONSCHEDULE where OBJID = '"+ json.description.properties.product_objid +"'",
        appName:'mes'
    }
    $.ajax({
        'url':'../../app/ExecuteSQL',
        'type':'post',
        'contentType': 'application/json',
        'data':JSON.stringify(param),
        'success':function(response){
			if(response.result.length>0){
				json.other_msg.push(response.result[0]);
			}
            if(!json.group){
                json['group'] = {
                    mesproductionschedule:[],
                    mesreportsheet:[],
                    curmeswarehouseitem:[],//当前物料
                    consumemeswarehouseitem:[],//消耗物料
                    qcpequipment:[],
                    mesordersheet:[],
                    mescontract:[]
                };
                for(var i=0;i<json.other_msg.length;i++){
                    if(json.other_msg[i].type.toLocaleLowerCase() != 'mesordersheet' && json.other_msg[i].type.toLocaleLowerCase() != 'mescontract'){
                        json.other_msg[i] = transferName(json.other_msg[i]);
                    }
                    if(json.other_msg[i].type.toLocaleLowerCase() == 'meswarehouseitem'){
                        if(json.other_msg[i].properties["物料耗用类型"] == "当前物料"){
                            json.group["curmeswarehouseitem"].push(json.other_msg[i]);
                        }
                        else {
                            json.group["consumemeswarehouseitem"].push(json.other_msg[i]);
                        }
                    }
                    else{
                        if(json.other_msg[i].properties){
                            json.group[json.other_msg[i].type.toLocaleLowerCase()].push(json.other_msg[i]);
                        }
                    }
                    
                }
            }
            if(json.group.mesreportsheet.length>0){
                if(json.group.mesreportsheet[0].properties['返修品数量']!=null){
                    json.group.mesreportsheet[0].properties['返修品数量'] = json.group.mesreportsheet[0].properties['返修品数量'] == ''?0:parseInt(json.group.mesreportsheet[0].properties['返修品数量']);
                }else{
                    json.group.mesreportsheet[0].properties['返修品数量'] = 0;
                }
                if(json.group.mesreportsheet[0].properties['废品数量']!=null){
                    json.group.mesreportsheet[0].properties['废品数量'] = json.group.mesreportsheet[0].properties['废品数量'] == ''?0:parseInt(json.group.mesreportsheet[0].properties['废品数量']);
                }else{
                    json.group.mesreportsheet[0].properties['废品数量'] = 0;
                }
                if(json.group.mesreportsheet[0].properties['零件对象标识'] != null){
                    var param1 = {
                        sql:"select * from PLM_PART where OBJID = '"+ json.group.mesreportsheet[0].properties['零件对象标识'] +"'",
                        appName:'mes'
                    }
                    $.ajax({
                        'url':'../../app/ExecuteSQL',
                        'type':'post',
                        'contentType': 'application/json',
                        'data':JSON.stringify(param1),
                        'success':function(res1){
                            if(res1.result && res1.result.length>0){
                                json.group.mesreportsheet[0].properties['零件对象标识'] = res1.result[0].properties.name;
                            }
                            show_nodedetail(json,target);
                        }
                    })
                }else{
                    json.group.mesreportsheet[0].properties['零件对象标识'] = '';
                    show_nodedetail(json,target);
                }
            }else{
                json.group.mesreportsheet.push({
                    properties:{
                        '零件对象标识':'',
                        '返修品数量':0,
                        '废品数量':0
                    }
                })
            }
        }
    })
    
}
function transferName(obj){
    var ret = {
        id:obj.id,
        properties:{},
        type:obj.type
    }
    if(obj.properties){
        var currentmata = metalist[obj.type.toLocaleLowerCase()];
        ret.properties = obj.properties;
        for(var k=0;k<currentmata.length;k++){
            if(obj.properties[currentmata[k].internalName.toLocaleLowerCase()]){
                ret.properties[currentmata[k].displayName] = obj.properties[currentmata[k].internalName.toLocaleLowerCase()];
            }
        }
    }else{
        delete ret.properties
    }
    return ret
}
        
